﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace MyVideoPlayer.Views
{
    /// <summary>
    /// AutoCloseMessageBox.xaml 的交互逻辑
    /// </summary>
    public partial class AutoCloseMessageBox : Window
    {
        public AutoCloseMessageBox(string message, int seconds = 2)
        {
            InitializeComponent();
            MessageText.Text = message;
            var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(seconds) };
            timer.Tick += (s, e) => { timer.Stop(); this.Close(); };
            timer.Start();
        }

        public static void Show(string message, int seconds = 2, Window? owner = null)
        {
            var box = new AutoCloseMessageBox(message, seconds);
            if (owner != null)
                box.Owner = owner;
            box.ShowDialog();
        }
    }
}
